package com.bicon.bdata_service_search.es.common.exception;

import com.bicon.bdata_service_search.es.common.result.ResultEnum;
import com.bicon.bdata_service_search.es.common.result.ResultUtil;
import org.elasticsearch.action.ActionRequestValidationException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * 描述:
 * 全局异常处理
 *
 * @author zhaoyu
 * @email zhaoyu@vv.cc
 * @create 2018-09-11 14:13
 */
@ControllerAdvice
public class GlobalExceptionHandler {
    @ExceptionHandler(Exception.class)
    @ResponseBody
//    String handleException(){
//        return "Exception Deal!";
//    }
    public Object defaultErrorHandler(HttpServletRequest req,Exception e){
        if (e instanceof ActionRequestValidationException){
            return ResultUtil.resultWithData(ResultEnum.PARAMERROR,e.getMessage());
        }
        return ResultUtil.error(10020,"system error");
    }
}